package io.github.wppli.webcocket.handler;

import io.github.wppli.webcocket.ErrorResponse;
import org.springframework.messaging.handler.annotation.MessageExceptionHandler;
import org.springframework.messaging.simp.annotation.SendToUser;
import org.springframework.web.bind.annotation.ControllerAdvice;

@ControllerAdvice
public class WebSocketExceptionHandler {

    @MessageExceptionHandler
    @SendToUser("/queue/errors")
    public ErrorResponse handleException(Exception ex) {
        ex.printStackTrace();
        return new ErrorResponse(ex.getMessage());
    }
}